<template>
  <a-layout id="components-layout-demo-side" style="min-height: 100vh">
    <a-layout-sider v-model="collapsed">
      <div class="logo"/>
      <a-menu :open-keys="openKeys" theme="dark" @openChange="onOpenChange" :default-selected-keys="['1']" mode="inline">
        <a-sub-menu key="sub1">
          <span slot="title"><a-icon type="line-chart"/><span>折线图</span></span>
          <a-menu-item key="1" @click="handleClick('/')">
            <span>
              <span>西安GDP</span></span>
          </a-menu-item>
        </a-sub-menu>

        <a-sub-menu key="sub2">
          <span slot="title"><a-icon type="pie-chart" /><span>饼图</span></span>
          <a-menu-item key="2" @click="handleClick('/pie')">
            <span>
              <span>西安人口</span></span>
          </a-menu-item>
        </a-sub-menu>

        <a-sub-menu key="sub3">
          <span slot="title"><a-icon type="bar-chart" /><span>柱状图</span></span>
          <a-menu-item key="3" @click="handleClick('/bar')">
            <span>
              <span>西安GDP</span></span>
          </a-menu-item>
        </a-sub-menu>

<!--        <a-sub-menu key="sub4">-->
<!--          <span slot="title"><a-icon type="heat-map" /><span>地图</span></span>-->
<!--          <a-menu-item key="4" @click="handleClick('/map')">-->
<!--            <span>-->
<!--              <span>西安区县人口</span></span>-->
<!--          </a-menu-item>-->
<!--        </a-sub-menu>-->

      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0"/>
      <a-layout-content style="margin: 0 16px">
        <a-breadcrumb style="margin: 16px 0">
        </a-breadcrumb>
        <div :style="{ padding: '24px', background: '#fff', minHeight: '100%' }">
          <router-view v-if="isRouterAlive"/>
        </div>
      </a-layout-content>
      <a-layout-footer style="text-align: center">
        北京理工大学珠海学院-数理学院 ©2021 Created by 王雨聪
      </a-layout-footer>
    </a-layout>
  </a-layout>
</template>

<script>
export default {
  name: "NavList",
  data() {
    return {
      collapsed: false,
      isRouterAlive: true,
      rootSubmenuKeys: ['sub1', 'sub2'],
      openKeys: ['sub1'],
    };
  },
  methods: {
    onOpenChange(openKeys) {
      const latestOpenKey = openKeys.find(key => this.openKeys.indexOf(key) === -1);
      if (this.rootSubmenuKeys.indexOf(latestOpenKey) === -1) {
        this.openKeys = openKeys;
      } else {
        this.openKeys = latestOpenKey ? [latestOpenKey] : [];
      }
    },
  handleClick(url) {
    this.$router.push({
      path: url
    })
  }
}
}
</script>

<style>
#components-layout-demo-side .logo {
  height: 0px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px;
}
</style>
